package com.laobiao.paChong.wanyijunshi;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.Test;

import com.laobiao.paChong.wanyijunshi.sina.model.SinaContentModel;
import com.laobiao.paChong.wanyijunshi.util.HttpClientUtil;

/**
 * 测试新浪军事频道
 * @author laobiao
 *
 */
public class testClientSina {

	@Test
	public void test(){
		Map<String, String> headers=new HashMap<>();
		headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36");
		headers.put("Accept-Language", "zh-CN,zh;q=0.8");
		headers.put("Accept-Encoding", "gzip, deflate");
		String s=HttpClientUtil.sendGetRequest("http://roll.mil.news.sina.com.cn/col/zgjq/index_1.shtml", null,headers,"GBK");
		Document doc = Jsoup.parse(s);
		Elements newsUl = doc.getElementsByClass("linkNews");
		for (Element element : newsUl) {
			
			Elements titls = element.getElementsByTag("a");
			
			for (Element element2 : titls) {
				System.out.println(element2.text()+"----"+element2.attr("href"));
			}
			
		}
	}
	
	@Test
	public void testTitleModel(){
		
		Map<String, String> headers=new HashMap<>();
		headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36");
		headers.put("Accept-Language", "zh-CN,zh;q=0.8");
		headers.put("Accept-Encoding", "gzip, deflate");
		String s=HttpClientUtil.sendGetRequest("http://roll.mil.news.sina.com.cn/col/gjjq/index_1.shtml", null,headers,"GBK");
		Document doc = Jsoup.parse(s);
		Elements newsUl = doc.select(".linkNews > li");
		for (Element element : newsUl) {
			
			try {
				SinaContentModel contentModel = new SinaContentModel(element);
				System.out.println(contentModel.getContent());
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	
}
